<div class="dropdown btn-group" ng-if="isBuyButtonVisible()">
  <button class="btn btn-default dropdown-toggle" data-toggle="dropdown">
    <span ng-if="!unit.maxCostMet().isZero()">Buy up to {{unit.maxCostMet().times(statTwin())|bignum}}</span>
    <span ng-if="unit.maxCostMet().isZero()" class="disabled">Can't buy</span>
    <span class="caret"></span>
  </button>
  <ul class="dropdown-menu" role="menu">
    <li ng-if="!unit.isCostMet()" role="presentation" class="disabled"><a role="menuitem">
      Can't buy
    </a></li>
    <li ng-if="unit.isCostMet()" role="presentation"><a role="menuitem" tabindex="-1" ng-click="buyUnit({unit:unit, num:fullnum()})" href="javascript:">
      Buy {{fullnum().times(statTwin())|bignum}}
    </a></li>
    <li ng-if="is25Visible()" role="presentation"><a role="menuitem" ng-click="buyMaxUnit({unit:unit, percent:0.25})" href="javascript:">
      Buy {{unit.maxCostMet(0.25).times(statTwin())|bignum}}
    </a></li>
    <li ng-if="unit.maxCostMet().greaterThan(1)" role="presentation"><a role="menuitem" ng-click="buyMaxUnit({unit:unit, percent:1})" href="javascript:">
      Buy {{unit.maxCostMet().times(statTwin())|bignum}}
    </a></li>

    <li ng-repeat-start="upgrade in unit.upgrades.list | filter:filterVisible" role="presentation" class="divider"></li>
    <li role="presentation" class="dropdown-header titlecase">{{upgrade.type.label}}</li>
    <li ng-if="!upgrade.isCostMet()" role="presentation" class="disabled"><a role="menuitem">
      Can't buy
    </a></li>
    <li ng-if="upgrade.isCostMet()" role="presentation"><a role="menuitem" tabindex="-1" ng-click="buyUpgrade({upgrade:upgrade, num:fullnum()})" href="javascript:">
      Buy {{fullnum()|bignum}}
    </a></li>
    <li ng-if="is25Visible(upgrade)" role="presentation"><a role="menuitem" ng-click="buyMaxUpgrade({upgrade:upgrade, percent:0.25})" href="javascript:">
      Buy {{upgrade.maxCostMet(0.25)|bignum}}
    </a></li>
    <li ng-repeat-end ng-if="upgrade.maxCostMet().greaterThan(1)" role="presentation"><a role="menuitem" ng-click="buyMaxUpgrade({upgrade:upgrade, percent:1})" href="javascript:">
      Buy {{upgrade.maxCostMet()|bignum}}
    </a></li>
  </ul>
</div>
